import React, { Component } from 'react';
import memory from '../../utils/memory';
import { Route,Switch,Redirect } from 'react-router-dom';
import { Layout } from 'antd';
import './admin.css';
import LeftNav from '../../components/left-nav/left-nav';
import Header from '../../components/header/header';
//引入二级路由组件
import Home from '../home/home';
import Category from '../category/category';
import Product from '../product/product';
import User from '../user/user';
import Role from '../role/role';
import Bar from '../echarts/bar';
import Line from '../echarts/line';
const { Footer, Sider, Content } = Layout;
//后台管理界面-路由组件
class Admin extends Component {
    render() {
        let user = memory.user; //获取用户信息
        console.log(user);
        if (!user.id) { //用户不存在时
            // return <Redirect to='/login' />
            this.props.history.replace('/login')
        }
        return (
            <Layout className='layout'>
                <Sider className='sider siderfa'>
                    <LeftNav className='left-nav' />
                </Sider>
                <Layout>
                    <Header></Header>
                    <Content style={{background:'white',margin:'15px',overflowY:'scroll'}}>
                        <Switch>
                            <Route path='/home' component={Home}></Route>
                            <Route path='/category' component={Category}></Route>
                            <Route path='/product' component={Product}></Route>
                            <Route path='/user' component={User}></Route>
                            <Route path='/role' component={Role}></Route>
                            <Route path='/bar' component={Bar}></Route>
                            <Route path='/line' component={Line}></Route>
                            <Redirect to='/home'></Redirect>
                        </Switch>
                       
                    </Content>
                    <Footer className='myfooter'>本系统推荐使用谷歌浏览器，以达到最佳操作体验</Footer>
                </Layout>
            </Layout>
        );
    }
}

export default Admin;